package com.hmall.search.web;

import com.hmall.common.clients.ItemClient;
import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.elasticsearch.client.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/search")
@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;


    /**
     * 自动补全
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    private List<String> suggestion(@RequestParam("key") String prefix) {

        return searchService.getSuggestion(prefix);
    }

    @PostMapping("/filters")
    private Map<String,List<String>> filters(@RequestBody RequestParams requestParams){
        return searchService.filters(requestParams);
    }

    @PostMapping("/list")
    private PageDTO<ItemDoc> search(@RequestBody RequestParams requestParams){
        return searchService.search(requestParams);
    }
}
